package com.example.carrierapp.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.carrierapp.ui.view.recycleview.XRecyclerView;
import com.example.carrierapp.util.ActivityUtil;
import com.example.carrierapp.util.DisplayUtil;
import com.example.carrierapp.util.GlideApp;
import com.example.carrierapp.util.RoundCornerTransform;
import com.example.lb.fingerdemo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class EmptyViewAdapter extends XRecyclerView.Adapter<EmptyViewAdapter.ViewHolder>{
    List<String> mList;
    private final RoundCornerTransform mRoundedCorners;
    public EmptyViewAdapter(List<String> competedWaybillPicPath, Context context) {
        mList=competedWaybillPicPath;
        mRoundedCorners = new RoundCornerTransform(DisplayUtil.dip2px(context, 4.0f));
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_empty_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.bindData(mList.get(position),mRoundedCorners);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends XRecyclerView.ViewHolder{
        @BindView(R.id.iv_pic)
        ImageView mIbPic;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
        public void bindData(String path, RoundCornerTransform mRoundedCorners)
        {
            GlideApp.with(itemView).load(path).placeholder(R.mipmap.icon_default_img).transform(mRoundedCorners).into(mIbPic);
            mIbPic.setOnClickListener(v -> {
                ActivityUtil.startSeePhoto(itemView.getContext(),path);
            });
        }

    }
}
